package com.xzakota.minesweeper.util;

import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

/**
 * 应用程序工具类
 *
 * @author Xzakota
 */
public class AppUtils {
    /**
     * @return 获取用户的应用程序数据目录
     */
    public static String getAppDataDir(String dataDirName) {
        String userDataDir;
        if (System.getProperty("os.name").toLowerCase().contains("win")) {
            userDataDir = System.getenv("APPDATA");
        } else {
            userDataDir = System.getProperty("user.home") + File.separator + "Library" + File.separator + "Application Support";
        }

        Path dataDirPath = Paths.get(userDataDir, dataDirName);

        if (!Files.exists(dataDirPath)) {
            try {
                Files.createDirectories(dataDirPath);
                System.out.println("Data directory created at: " + dataDirPath.toAbsolutePath());
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }

        return dataDirPath.toAbsolutePath().toString();
    }
}
